<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <!--{include file='comm/comm_editor.tpl'}-->
    <!--{include file='comm/comm_region.tpl'}-->
    <!--{include file='comm/comm_cal.tpl'}-->
    <!--{include file="comm/comm_multiselect.tpl"}-->

    <title>订单结算</title>
</head>
<style>
    .ui-multiselect{ width: 165px !important;}
</style>
<body>
<div class="container">

        <div class="comm_content">

            <div class="search-box">
                <div style="position:relative">
                    <form id="search_form" class="form-inline" onsubmit="return false;">
                        <table>
                            <tbody>
                            <tr>
                                <td>
                                    <span>订单编号：<input type="text" id="bill_code" class="form-control input-sm"  name="bill_code" value="" style="width:120px;"/></span>
                                </td>

                                <td>
                                    <span>配送日期：<input id="send_date" class="form-control input-sm"  name="send_date" value="<!--{$currentDate|default:''}-->" type='text' style="width:100px;" readonly ></span>
                                    <button type="button" class="btn btn-default btn-sm" onclick="orderSettlement.timeClear();">清 空</button>
                                </td>

                                <td>
                                     <span>配送开始时间：<select id="send_start_time" class="form-control input-sm"  name="send_start_time" style="width:95px;">
                                             <option value="">请选择</option>
                                             <!--{foreach from=$sendStartTime key=myId item=star}-->
                                             <!--{if $myId == 0}-->
                                             <option value="<!--{$star.itemName}-->" selected><!--{$star.itemName}--></option>
                                             <!--{/if}-->
                                             <option value="<!--{$star.itemName}-->"><!--{$star.itemName}--></option>
                                             <!--{/foreach}-->
                                         </select>
                                    </span>
                                </td>

                                <td>
                                    <span>配送结束时间：<select id="send_start_time_end" class="form-control input-sm"  name="send_start_time_end" style="width:95px;">
                                            <option value="">请选择</option>
                                            <!--{foreach from=$sendEndTime item=end}-->
                                            <!--{if $end.itemName == $end_time}-->
                                            <option value="<!--{$end.itemName}-->" selected><!--{$end.itemName}--></option>
                                            <!--{/if}-->
                                            <option value="<!--{$end.itemName}-->"><!--{$end.itemName}--></option>
                                            <!--{/foreach}-->
                                        </select>
                                    </span>
                                </td>

                                <td>
                                    <span>
                                        配送对账：<select id="is_reconciliation" class="form-control input-sm"  name="is_reconciliation" style="width:95px;">
                                            <option value="">请选择</option>
                                            <option value="1">是</option>
                                            <option value="0">否</option>
                                        </select>
                                    </span>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                     <span>
                                        是否有应收：<select id="receivable" class="form-control input-sm"  name="receivable" style="width:95px;">
                                             <option value="">请选择</option>
                                             <option value="1">是</option>
                                             <option value="0">否</option>
                                         </select>
                                    </span>
                                </td>
                                <td>
                                     <span>城市：<select id="deliver_cityid" class="form-control input-sm"  name="deliver_cityid" style="width:100px;">
                                             <option value="">请选择</option>
                                         </select>
                                    </span>
                                </td>
                                <td>
                                    <span>配送站：<select id="distribution_id" class="form-control input-sm"  name="distribution_id" style="width:120px;">
                                            <option value="">请选择</option>
                                        </select>
                                    </span>
                                </td>
                                <td>
                                    <span>
                                        配送员：<select id="distribution_technician_id" class="form-control input-sm"  name="distribution_technician_id" style="width:100px;">
                                            <option value="">请选择</option>
                                        </select>
                                    </span>
                                </td>
                                <td>
                                     <span>
                                        是否分配配送员：<select id="technician_id" class="form-control input-sm"  name="technician_id" style="width:100px;">
                                             <option value="">请选择</option>
                                             <option value="1">是</option>
                                             <option value="0">否</option>
                                         </select>
                                    </span>
                                </td>

                            </tr>
                            <tr>
                                <td>
                                    <span>
                                        订单品牌：<select class="form-control input-sm" name="billPlatform">
                                            <option value="all">全部</option>
                                            <option value="1">自营</option>
                                            <option value="2">澳粒</option>
                                        </select>
                                    </span>
                                </td>
                                <td>
                                    <span>订单类型：<select id="billType" class="form-control input-sm"  name="billType" style="width:120px;">
                                            <option value="all">全部</option>
                                            <!--{foreach from=$global_array.bill_type item=bill_type_name key=bill_type}-->
                                                <option value="<!--{$bill_type}-->"><!--{$bill_type_name.name}--></option>
                                            <!--{/foreach}-->
                                        </select>
                                    </span>
                                    <input type="hidden" id="bill_type" name="bill_type" value=""/>
                                </td>
                                <td>
                                    <span>订单状态：<select id="bill_status" class="form-control input-sm"  name="bill_status" style="width:120px;">
                                            <option value="all">全部</option>
                                            <!--mod by yim.hu 20141127 FUN-BK-0030 订单分配页面增加标识退货的订单--start -->
                                     
                                            <option value="5">已下车</option>
                                            <option value="6">已出仓</option>
                                            <option value="7">已完成</option>
                                            <!--mod by yim.hu 20141127 FUN-BK-0030 订单分配页面增加标识退货的订单--end -->
                                        </select>
                                    </span>
                                    <input type="hidden" id="billStatus" name="billStatus" value=""/>
                                </td>

                                <td>
                                     <span>
                                        发票：<select id="invoice" class="form-control input-sm"  name="invoice" style="width:100px;">
                                             <option value="">请选择</option>
                                             <option value="1">是</option>
                                             <option value="0">否</option>
                                         </select>
                                    </span>
                                </td>
                                <td colspan="3" style="text-align: right;">
                                    <input type="button" value="查询" class="btn btn-primary" onclick="orderSettlement.search();" />
                                    <input type="button" value="重置" class="btn btn-warning" onclick="orderSettlement.clear();" />
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>

            <table id="flex" style="display:none"></table>

        </div>


    <!--{include file='comm/footer.tpl'}-->

</div>

    <div id="pop" style="display:none">
        <div id="select-content">
                <div class="form-inline">
                    <table>
                        <tbody id="rejectCause">
                        <tr>
                            <td>
                                <span>订单号：<input type="text" id="billCode" class="form-control input-sm"  name="bill_code" value="" style="width:177px;" readonly/></span>
                                <span>订单总额：<input type="text" id="billTotalMoney" class="form-control input-sm"  name="billTotalMoney" value="" style="width:100px;" readonly/></span>
                                <span>已付金额：<input type="text" id="billPaidAmount" class="form-control input-sm"  name="billPaidAmount" value="" style="width:100px;" readonly/></span>
                                <span>未付金额：<input type="text" id="billUnpaidAmount" class="form-control input-sm"  name="billUnpaidAmount" value="" style="width:100px;" readonly/></span>
                                <span>配送员：<input type="text" id="deliveries" class="form-control input-sm"  name="deliveries" value="" style="width:100px;" readonly/></span>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            <form id="reconciliationForm" name="reconciliationForm" onsubmit="return false;">
                <input type="hidden" id="bill_no" name="bill_no" value="" />
                <table class="table table-bordered table-hover" style="margin-top: 19px;">
                    <thead>
                    <tr>
                        <th>支付方式</th>
                        <th>应付金额</th>
                        <th>已付金额</th>
                        <th>未付金额</th>
                        <th>POS流水号</th>
                        <th>POS机号</th>
                        <th>现金卡号</th>
                        <th>付款金额</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="billPay">

                    </tbody>
                </table>
                <div>
                    <select class="form-control input-sm" style="width:180px;" id="changePayment">
                        <!--{foreach from=$pay_ment_array item=payment}-->
                        <option value="<!--{$payment.id}-->" flg="<!--{$payment.type}-->"><!--{$payment.name}--></option>
                        <!--{/foreach}-->
                    </select>
                    <span>
                        <button type="button" class="btn btn-primary btn-sm" style="float:left; margin-left: 209px; margin-top: -30px;" onclick="orderSettlement.addTable();">新增</button>
                    </span>
                </div>
                <div id="addPayTable" style="display: none;">
                    <table class="table table-bordered table-hover" style="margin-top: 19px;">
                        <thead>
                        <tr>
                            <th>支付方式</th>
                            <th>应付金额</th>
                            <th>已付金额</th>
                            <th>未付金额</th>
                            <th>POS流水号</th>
                            <th>POS机号</th>
                            <th>现金卡号</th>
                            <th>付款金额</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody id="payTbody">

                        </tbody>
                    </table>
                </div>
                <div class="form-group" style="margin-top: 19px;">
                    <label for="bill_checking_remark" class="col-sm-2 control-label"> 对账备注：</label>
                    <div class="col-sm-10">
                        <textarea  class="form-control" id="bill_checking_remark" name="bill_checking_remark" placeholder="请输入对账备注" ></textarea>
                    </div>
                </div>
            </form>
        </div>
    </div>


<script type="text/javascript" src="/inc/config/default/region.min.js"></script>
<script type="text/javascript" src="/framework/ebsig/js/region.change.min.js"></script>
<!--baidu map-->
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=8d5812593e46968cd655b1a6c1af9c93"></script>

<script type="text/javascript">

    $('#send_date').datepicker();

    var table_id = <!--{$table_id}-->;

    var fixed_json = <!--{$fixed_json}-->;

    $("#flex").flexigrid({
        url:"/invokingAjax-backend/send/orderSettlement.ajax?operFlg=1",
        dataType: "json",
        colModel : fixed_json,
        <!--{if $edit_permission}-->
        buttons : [
            {name: "全选", bclass: "checkAll", onpress : "E.checkAllList"},
            {separator: true},
            {name: "取消全选", bclass: "cancelCheckAll", onpress : "E.cancelCheckAllList"},
            {separator: true},
            {name: "出仓", bclass: "add", onpress : "orderSettlement.outbound"},
            {separator: true},
            {name: "批量对账", bclass: "add", onpress : "orderSettlement.batchReconciliation"}
        ],
        <!--{/if}-->
        sortname: "createTime",
        sortorder: "desc",
        usepager: true,
        rp: 50,
        useRp: true,
        showTableToggleBtn: true,
        autoload: true,
        onSubmit: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt});
            return true;
        },

        //拉伸宽度后触发
        onColResize:function(){

            var last_cid = arguments[0];
            var width = arguments[1];

            E.ajax_get({
                url:'/invokingAjax-backend/system/flexigrid.ajax?operFlg=1',
                data:{
                    table_id:table_id,
                    last_cid:last_cid,
                    width:width
                },
                call:function( o ){ }

            });

        },

        //隐藏后触发
        onToggleCol:function(){

            var cid = arguments[0];
            var hide = arguments[1];

            E.ajax_get({
                url:'/invokingAjax-backend/system/flexigrid.ajax?operFlg=3',
                data:{
                    table_id:table_id,
                    cid:cid,
                    hide:hide
                },
                call:function( o ){ }

            });
        },

        //拖拽后触发
        onDragCol:function(){

            var cid = arguments[0];
            var last_cid = arguments[1];

            E.ajax_get({
                url:'/invokingAjax-backend/system/flexigrid.ajax?operFlg=2',
                data:{
                    table_id:table_id,
                    cid:cid,
                    last_cid:last_cid
                },
                call:function( o ){ }

            });

        }

    });


    $('#billType').multiselect();
    $('#bill_status').multiselect();

    var orderSettlement = {

        pay_type_index: 0,

        pay_type_array:{ },

        //搜索
        search: function() {

            var billType_values = $("#billType").multiselect("getChecked").map(function(){ return this.value;}).get();
            $('#bill_type').val(billType_values);
            var bill_status_values =  $("#bill_status").multiselect("getChecked").map(function(){ return this.value;}).get();
            $('#billStatus').val(bill_status_values);

            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({newp: 1, params: dt}).flexReload();
        },

        //重置
        clear: function(){
            document.forms['search_form'].reset();
            $('#billType').multiselect("refresh");
            $('#bill_status').multiselect("refresh");
            this.search();
        },

        timeClear: function() {
            $('#send_date').val('');
        },

        //重新加载
        load: function() {
            $("#flex").flexReload();
        },

        //订单详情
        billview: function( bill_no ) {
            window.open('/quanliadmin/app/bill/billSearch.pscript?operFlg=9&bill_no=' + bill_no);
        },

        //获取出仓订单
        outbound: function(){

            outbound_array: '';

            var outbound_obj = $('#flex').find('tr.trSelected');
            if (outbound_obj.length == 0) {
                E.alert('请选择要出仓的订单');
            } else {

                var temp_array = new Array();
                var error_flg = 0;

                $.each(outbound_obj, function(k, v) {
                    var id = $(v).attr('id').replace('row', '');
                    if( id != ' ' ){
                        temp_array.push($(v).attr('id').replace('row', ''));
                    }

                });

                this.outbound_array = temp_array;
                E.confirm('您确认要对选中的订单出仓吗？', 'orderSettlement.execute');

            }

        },
        //出仓操作
        execute: function() {
            E.loadding.open('正在操作，请稍候...');
            E.ajax_post({
                url: '/invokingAjax-backend/send/orderSettlement.ajax?operFlg=2',
                data: {
                    outbound_array: this.outbound_array
                },
                call: 'orderSettlement.result'
            });
        },

        //订单批量对账
        batchReconciliation: function(){

            batchReconciliation_array: '';

            var batchReconciliation_obj = $('#flex').find('tr.trSelected');
            if (batchReconciliation_obj.length == 0) {
                E.alert('请选择要对账的订单');
            } else {

                var temp_array = new Array();
                var error_flg = 0;

                $.each(batchReconciliation_obj, function(k, v) {
                    var id = $(v).attr('id').replace('row', '');
                    if( id != ' ' ){
                        temp_array.push($(v).attr('id').replace('row', ''));
                    }
                });

                this.batchReconciliation_array = temp_array;
                E.confirm('您确认要对选中的订单对账吗？', 'orderSettlement.become');

            }
        },

        //订单批量对账执行
        become: function(){
            E.loadding.open('正在操作，请稍候...');
            E.ajax_post({
                url: '/invokingAjax-backend/send/orderSettlement.ajax?operFlg=4',
                data: {
                    batchReconciliation_array: this.batchReconciliation_array
                },
                call: 'orderSettlement.result'
            });
        },

        //返回结果
        result: function( o ) {

            E.loadding.close();
            if (o.code == 200) {
                E.popup.close();
                E.alert(o.message, 2, 'orderSettlement.load');
            } else {
                E.alert(o.message);
            }

        },

        //点击对账按钮弹出层
        reconciliation: function( bill_code,bill_no ){

            //调用打开弹出层公共JS方法
            E.popup.open({
                id:"pop",   		 //获取id为"pop"元素内的HTML
                title: "配送对账",       //弹出层标题
                css: "width:1000px;",     //设置弹出层样式
                btnName: "完成对账",         //执行“确定”操作的按钮名称
                btnCall:"orderSettlement.check();"  //点击确定后执行的方法
            });

            //配送对账时查询订单相关数据
            E.ajax_get({
                url: '/invokingAjax-backend/send/orderSettlement.ajax?operFlg=5',
                data: {
                    bill_no: bill_no
                },
                call: function( obj ) { 

                    if(obj.code == 200){

                        $('#billCode').val(bill_code);
                        $('#bill_no').val(bill_no);
                        $('#billTotalMoney').val(obj.data.bill_money);
                        $('#billPaidAmount').val(obj.data.bill_received_money);
                        $('#billUnpaidAmount').val(obj.data.bill_receivable_money);
                        $('#deliveries').val(obj.data.distribution_technicia);
                        if(obj.data.bill_reject_cause){
                            var html1="";
                            html1 +='<tr><td><span>驳回原因：'+obj.data.bill_reject_cause+'<span><td><tr>';
                            $('#rejectCause').append(html1);
                        }
                        $('#reject_cause').val();
                        var html = "";
                        $.each(obj.data.pay_data, function(i,p){
                            if(p.type == 6){
                                html += '<input type="hidden" name="billPayNo[]" value="'+ p.bill_pay_no +'" />';
                                html += '<input type="hidden" name="type[]" value="'+ p.type +'" />';
                                html += '<input type="hidden" name="pay_ment[]" value="'+ p.payTypeName +'" />';
                                html += ' <tr><td>'+ p.payTypeName +'</td>';
                                html += '<td>'+obj.data.bill_coupon_money+'</td>';
                                html += '<td>'+obj.data.bill_coupon_money+'</td>';
                                html += '<td>0</td>';
                                html += '<td><input type="hidden" class="form-control" name="posSerialNumber[]" value="" /></td>';
                                html += '<td><input type="hidden" class="form-control" name="posCut[]" value="" /></td>';
                                html += '<td><input type="hidden" name="pay_type[]" value="" /></td>';
                                html += '<td><input type="hidden" class="form-control" name="get_money[]" value="" /></td>';
                                html += '<td></td></tr>';
                            }
                            if(p.type == 4){
                                html += '<input type="hidden" name="billPayNo[]" value="'+ p.bill_pay_no +'" />';
                                html += '<input type="hidden" name="type[]" value="'+ p.type +'" />';
                                html += '<input type="hidden" name="pay_ment[]" value="'+ p.payTypeName +'" />';
                                html += ' <tr><td>'+ p.payTypeName +'</td>';
                                html += '<td>'+p.pay_amount+'</td>';
                                html += '<td>'+p.pay_amount+'</td>';
                                html += '<td>0</td>';
                                html += '<td><input type="hidden" class="form-control" name="posSerialNumber[]" value="" /></td>';
                                html += '<td><input type="hidden" class="form-control" name="posCut[]" value="" /></td>';
                                html += '<td><input type="hidden" name="pay_type[]" value="" /></td>';
                                html += '<td><input type="hidden" class="form-control" name="get_money[]" value="" /></td>';
                                html += '<td></td></tr>';
                            }
                            if(p.type == 5){
                                html += '<input type="hidden" name="billPayNo[]" value="'+ p.bill_pay_no +'" />';
                                html += '<input type="hidden" name="type[]" value="'+ p.type +'" />';
                                html += '<input type="hidden" name="pay_ment[]" value="'+ p.payTypeName +'" />';
                                html += ' <tr><td>'+ p.payTypeName +'</td>';
                                html += '<td>'+p.pay_amount+'</td>';
                                html += '<td>'+p.pay_amount+'</td>';
                                html += '<td>0</td>';
                                html += '<td><input type="hidden" class="form-control" name="posSerialNumber[]" value="" /></td>';
                                html += '<td><input type="hidden" class="form-control" name="posCut[]" value="" /></td>';
                                html += '<td><input type="hidden" name="pay_type[]" value="" /></td>';
                                html += '<td><input type="hidden" class="form-control" name="get_money[]" value="" /></td>';
                                html += '<td></td></tr>';
                            }
                            if(p.type == 2){
                                html += '<input type="hidden" name="billPayNo[]" value="'+ p.bill_pay_no +'" />';
                                html += '<input type="hidden" name="type[]" value="'+ p.type +'" />';
                                html += '<input type="hidden" name="pay_ment[]" value="'+ p.payTypeName +'" />';
                                html += ' <tr><td>'+ p.payTypeName +'</td>';
                                html += '<td>'+ p.pay_amount+'</td>';
                                html += '<td>'+ obj.data.bill_online_money +'</td>';
                                html += '<td>'+ p.pay_online_amount +'</td>';
                                html += '<td><input type="hidden" class="form-control" name="posSerialNumber[]" value="" /></td>';
                                html += '<td><input type="hidden" class="form-control" name="posCut[]" value="" /></td>';
                                html += '<td><input type="hidden" name="pay_type[]" value="" /></td>';
                                html += '<td><input type="hidden" class="form-control" name="get_money[]" value="" /></td>';
                                html += '<td></td></tr>'
                            }
                            if(p.type == 7){
                                html += '<input type="hidden" name="billPayNo[]" value="'+ p.bill_pay_no +'" />';
                                html += '<input type="hidden" name="type[]" value="'+ p.type +'" />';
                                html += '<input type="hidden" name="pay_ment[]" value="'+ p.payTypeName +'" />';
                                html += ' <tr class="pay_type_line"><td>'+ p.payTypeName +'</td>';
                                html += '<td>'+p.pay_amount+'</td>';
                                html += '<td>'+p.pay_amount+'</td>';
                                html += '<td>0<input type="hidden" name="pay_type[]" value="'+p.type+'" /></td>';

                                //update by sunqiang 2014/9/30
                                //pay_type不清楚该值的作用，但是因为该值影响到现金卡的加载
                                //原代码：html += '<td>0<input type="hidden" name="pay_type[]" value="'+pay_type+'" /></td>';


                                html += '<td><input type="hidden" class="form-control" name="posSerialNumber[]" value="" /></td>';
                                html += '<td><input type="hidden" class="form-control" name="posCut[]" value="" /></td>';
                                html += '<td><input type="text" class="form-control" style="height:28px;" id="casCardNumber" name="casCardNumber" value="" /></td>';
                                html += '<td><input type="hidden" class="form-control" name="get_money[]" value="" /></td>';
                                html += '<td></td></tr>';
                            }
                            if(p.type == 1){
                                if(p.payment_method_type == 1){
                                    html += ' <tr class="pay_type_line"><td>'+p.payment_method_name+'</td>';
                                    html += '<td>'+obj.data.bill_receivable_money+'</td>';
                                    html += '<td>0<input type="hidden" name="pay_type[]" value="" /></td>';
                                    html += '<td>'+obj.data.bill_receivable_money+'</td>';
                                    html += '<td><input type="hidden" class="form-control" name="posSerialNumber[]" value="" /><input type="hidden" name="billPayNo[]" value="'+ p.bill_pay_no +'" /></td>';
                                    html += '<td><input type="hidden" class="form-control" name="posCut[]" value="" /><input type="hidden" name="type[]" value="'+ p.payment_method_id +'" /></td>';
                                    html += '<td><input type="hidden" name="pay_ment[]" value="'+p.payment_method_name+'" /></td>';
                                    html += '<td><input type="text" class="form-control" style="width:80px;height:28px;" name="get_money[]" value="" /></td>';
                                    html += '<td id="new_'+orderSettlement.pay_type_index+'"><span style="border: 1px; border-radius: 4px; width: 70px; height: 30px; padding: 6px 9px; background:#3071a9;"><a  href="javascript: void(0);"onclick="orderSettlement.removeTable('+orderSettlement.pay_type_index+');"><font style="color:#fff">删除</font></a></span></td></tr>';
                                }else{
                                    html += ' <tr class="pay_type_line"><td>' + p.payment_method_name +'</td>';
                                    html += '<td>'+obj.data.bill_receivable_money +'</td>';
                                    html += '<td>0<input type="hidden" name="pay_type[]" value="" /></td>';
                                    html += '<td>'+ obj.data.bill_receivable_money +'</td>';
                                    html += '<td><input type="text" class="form-control" style="width:100px;height:28px;" name="posSerialNumber[]" value="" /><input type="hidden" name="billPayNo[]" value="'+ p.bill_pay_no +'" /></td>';
                                    html += '<td><input type="text" class="form-control" style="width:100px;height:28px;" name="posCut[]" value="" /><input type="hidden" name="type[]" value="'+ p.payment_method_id +'" /></td>';
                                    html += '<td><input type="hidden" name="pay_ment[]" value="'+p.payment_method_name+'" /></td>';
                                    html += '<td><input type="text" class="form-control" style="width:80px;height:28px;" name="get_money[]" value="" /></td>';
                                    html += '<td id="new_'+orderSettlement.pay_type_index+'"><span style="border: 1px; border-radius: 4px; width: 70px; height: 30px; padding: 6px 9px; background:#3071a9;"><a  href="javascript: void(0);"onclick="orderSettlement.removeTable('+orderSettlement.pay_type_index+');"><font style="color:#fff">删除</font></a></span></td></tr>';
                                }
                            }
                        });
                        $('#billPay').html(html);
                }
            }
        });
    },

    //对账操作
    check: function(){
        dt: "",
                this.dt = E.getFormValues("reconciliationForm");

        E.loadding.open("正在对账，请稍后...");
        E.ajax_post({
            url: '/invokingAjax-backend/send/orderSettlement.ajax?operFlg=100',
            data:this.dt,
            call: "orderSettlement.result"
        });
    },


    //点击新增对账支付方式
        addTable: function(){

            //配送方式条数索引加1
            orderSettlement.pay_type_index++;

            var type = $("#changePayment").val();

            var pay_type = $('#changePayment').find("option:selected").attr("flg");
            var pay_ment = $('#changePayment').find("option:selected").text();
            html = "";
            html += ' <tr class="pay_type_line"><td>'+pay_ment+'</td>';
            html += '<td><input type="hidden" name="type[]" value="'+type+'" /></td>';
            html += '<td><input type="hidden" name="pay_ment[]" value="'+pay_ment+'" /></td>';
            html += '<td><input type="hidden" name="billPayNo[]" value="" /></td>';
            if(pay_type == 1){
                html += '<td><input type="hidden" class="form-control" name="posSerialNumber[]" value="" /></td>';
                html += '<td><input type="hidden" class="form-control" name="posCut[]" value="" /></td>';
            }else{
                html += '<td><input type="text" class="form-control" style="width:100px;height:28px;" name="posSerialNumber[]" value="" /></td>';
                html += '<td><input type="text" class="form-control" style="width:100px;height:28px;" name="posCut[]" value="" /></td>';
            }
            html += '<td><input type="hidden" name="pay_type[]" value="'+pay_type+'" /></td>';
            html += '<td><input type="text" class="form-control" style="width:80px;height:28px;" name="get_money[]" value="" /></td>';
            html += '<td id="new_'+orderSettlement.pay_type_index+'"><span style="border: 1px; border-radius: 4px; width: 70px; height: 30px; padding: 6px 9px; background:#3071a9;"><a  href="javascript: void(0);"onclick="orderSettlement.removeTable('+orderSettlement.pay_type_index+');"><font style="color:#fff">删除</font></a></span></td></tr>';

            $('#payTbody').append(html);
            $('#addPayTable').css('display','block');
        },

        //点击删除新增对账支付方式
        removeTable: function(i){
            $('#new_'+i).parent().remove();
//            $('#addPayTable').css('display','none');
        }

    }

    $(window).ready(function() {
//显示城市
        $("#deliver_cityid").html("");

        var cityHtml = '<option value="">请选择</option>';

        $.ajax({
            type: "post",
            url: "/invokingAjax-comm/bill/distribution.ajax?operFlg=1",
            dataType: "json",
            data: "",
            success: function( result_obj ) {
                if(result_obj.code == 200){
                    if(result_obj.data == ""){
                        $('#deliver_cityid').html(cityHtml);
                    }else{
                        var selected = "";
                        if(result_obj.data.length == 1){
                            selected = "selected";
                        }
                        $.each(result_obj.data, function(i,val){
                            cityHtml +='<option value="'+val.id+'" '+selected+'>'+val.name+'</option>';
                        });
                        $('#deliver_cityid').html(cityHtml);
                        $('#deliver_cityid').trigger("change");
                    }
                }else{
                    E.alert(result_obj.message);
                }
            }
        });

        //城市配送站联动
        $(document).on('change', '#deliver_cityid', function() {

           $('#distribution_id').html("");
            $('#distribution_technician_id').html('');

            var deliver_cityid = $('#deliver_cityid').children('option:selected').val();
            var distributionHtml = '<option value="">请选择</option>';
            var technicianHtml = '<option value="">请选择</option>';
            $.ajax({
                type: "post",
                url: "/invokingAjax-comm/bill/distribution.ajax?operFlg=2",
                dataType: "json",
                data: {deliver_cityid: deliver_cityid},
                success: function( obj ) {
                    if(obj.code ==200 && obj.data != null){
                        var selected = "";
                        if(obj.data.length == 1){
                            selected = "selected";
                        }
                        $.each(obj.data, function(i,val){
                            distributionHtml +='<option value="'+val.distribution_id+'" '+selected+'>'+val.distribution_name+'</option>';
                        });
                        $('#distribution_id').html(distributionHtml);
                        $('#distribution_technician_id').html(technicianHtml);
                    }else{
                        distributionHtml += '';
                        $('#distribution_id').html(distributionHtml);
                        $('#distribution_technician_id').html(technicianHtml);
                    }
                    $("#distribution_id").trigger("change");
                }
            });
        });
//城市，配送站，配送员联动
        $(document).on('change', '#distribution_id', function() {

            $('#distribution_technician_id').html('');
            var distribution_id = $('#distribution_id').children('option:selected').val();
            var technicianHtml = '<option value="">请选择</option>';
            $.ajax({
                type: "post",
                url: "/invokingAjax-comm/bill/distribution.ajax?operFlg=3",
                dataType: "json",
                data: {distribution_id: distribution_id},
                success: function( o ) {
                    if(o.code ==200 && o.data != null){
                        $.each(o.data, function(i,val){
                            technicianHtml +='<option value="'+val.distribution_technician_id+'">'+val.distribution_technician_name+'</option>';
                        });
                        $('#distribution_technician_id').html(technicianHtml);
                    }else{
                        technicianHtml += '';
                        $('#distribution_technician_id').html(technicianHtml);
                    }
                }
            });
        });

    });
//    $('#deliver_cityid').multiselect();
//    $('#distribution_id').multiselect();
//    $('#technician_id').multiselect();



</script>

</body>

</html>
